<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head>
    <th:block th:include="include :: header('盘点入库作业管理')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <style>

    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="col-sm-12 search-collapse">
        <form id="user-form">
            <div class="select-list">
                <ul>
                    <input type="text" name="inOut" value="5" hidden/>
                    <li>
                        <label>仓库：</label>
                        <select name="warehouseId" th:with="type=${@dict.getType('is_house')}" required>
                            <!--<option value="">请选择</option>-->
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </li>
                    <li>
                        <label>作业状态：</label>
                        <select name="status" th:with="type=${@dict.getType('job_status')}">
                            <!--                            <option value="">所有</option>-->
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </li>
                    <li>
                        <label>任务号：</label><input type="text" name="taskNo" />
                    </li>
                    <!--<li>-->
                        <!--<label>托盘条码：</label><input type="text" name="trayCode"/>-->
                    <!--</li>-->

                    <li>
                        <label>起止时间：</label><input type="text" placeholder="请单击选择开始时间：" name="startTime" id="startTime"/>---
                        <input type="text" placeholder="请单击选择结束时间：" name="finishTime" id="finishTime"/>
                    </li>
                    <li>
                        出入库类型：
                        <select id="inOrOut" name="inOrOut" th:height="300px">
                            <option value="4">盘点入库</option>
                        </select>
                    </li>
                    <li>
                        <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                class="fa fa-search"></i>&nbsp;搜索</a>
                        <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                class="fa fa-refresh"></i>&nbsp;重置</a>
                    </li>
                </ul>
            </div>
        </form>
    </div>
    <div class="btn-group-sm" id="toolbar" role="group">
        <!--<a class="btn btn-success" onclick="changeJobStatus()" shiro:hasPermission="mydo:mydojob:changeJobStatus">-->
            <!--<i class="fa fa-caret-down"></i> 更改作业状态-->
        <!--</a>-->
        <a class="btn btn-success" onclick="handFinish()" >
            <i class="fa fa-plus"></i> 手动完成
        </a>
        <a class="btn btn-danger" style="background-color: red" onclick="handInvalid()"
           shiro:hasPermission="mydo:mydojob:handInvalid">
            <i class="fa fa-trash-o"></i> 手动作废
        </a>
    </div>

    <div id="div1" style="height: 350px" class="col-sm-8 select-table">
        <table id="bootstrap-table" data-mobile-responsive="true"></table>
    </div>
    <div id="div2" style="height: 350px" class="col-sm-8 select-table">
        <table id="bootstrap-table2" data-mobile-responsive="true"></table>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var jobExeDatas = [[${@dict.getType('job_execution_in')}]];
    var jobStatusDatas = [[${@dict.getType('job_status')}]];
    var jobTypeDatas = [[${@dict.getType('in_or_out')}]];
    var jobExeDatas = [[${@dict.getType('job_execution_in')}]];
    var product_status = [[${@dict.getType('product_status')}]];
    var warehouse = [[${@dict.getType('is_house')}]];
    var prefix = ctx + "mydo/mydojobin"


    layui.use('laydate', function () {
        var laydates = layui.laydate;
        laydates.render({
            elem: '#beginDate'
            , type: 'datetime',
            /* ,range: '到' */
            format: 'yyyy-MM-dd HH:mm:ss'
        })
    })

    layui.use('laydate', function () {
        var laydates = layui.laydate;
        laydates.render({
            elem: '#endDate'
            , type: 'datetime',
            /* ,range: '到' */
            format: 'yyyy-MM-dd HH:mm:ss'
        })
    })
//子表
    var options2 = {
    	url:"",
        updateUrl: ctx + "mydo/stockindetail/edit/{id}",
        search: false,
        showRefresh: true,
        showColumns: true,
        minimumCountColumns: 2,
        clickToSelect: true,//是否启用点击选中行
        height: $("#div2").height() / 1,
        sortName: "jobDetailId",
        sortOrder: "asc",
        modalName: "入库单据子表",
        method: 'post',
        striped: true, //是否显示行间隔色
        pagination: true,//显示分页
        sidePagination: "client",
        pageNumber: 1,
        pageSize: 15,
        pageList: [10, 25],
        singleSelect: true,
        columns:
            [{
                checkbox: true,
            },
                {
                    field: 'jobDetailId',
                    title: '子表编号',
                    align: 'center'
                },
                {
                    field: 'jobId',
                    title: '主表编号',
                    align: 'center'
                },


                {
                    field: 'productGuid',
                    title: '物资guid',
                    visible: false
                },
                {
                    field: 'productId',
                    title: '物品编号',
                    align: 'center',

                },
                {
                    field: 'productName',
                    title: '物品名称',
                    align: 'center',
                },
                {
                    field: 'lotNo',
                    title: '批号',
                    visible: true
                },
                {
                    field: 'productStatus',
                    title: '物品状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(product_status, value);
                    }
                },
                {
                    field: 'printDate',
                    title: '生产时间',
                    visible: true
                },
                {
                    field: 'spec',
                    title: '供应商',
                    align: 'center',
                },
                {
                    field: 'inQuantity',
                    title: '数量',
                    align: 'center'
                },
                {
                    field: 'inQuantityX',
                    title: '重量',
                    align: 'center'
                },
                {
                    field: 'inOrOutId',
                    title: '入库单据',
                    visible: false
                },
                {
                    field: 'inOrOutDId',
                    title: '入库子单据',
                    visible: false

                },

            ],
        onLoadSuccess(data) {
            switch (data.code) {
                case  500:
                    options2.url = "";
                    $('#bootstrap-table2').bootstrapTable("removeAll")
                    $.modal.alertWarning("查询出错！");
                    break;
                default:
                    break;
            }
        },
    }
    $('#bootstrap-table2').bootstrapTable(options2)
    //主表
    var options = {
        url: prefix + "/pdinJoblist",
        detailView: false,//父子表
        height: $("#div1").height() / 1,
        search: false,
        showRefresh: true,
        showColumns: true,
        minimumCountColumns: 2,
        clickToSelect: true,//是否启用点击选中行
        createUrl: prefix + "/add",
        updateUrl: prefix + "/edit/{id}",
        removeUrl: prefix + "/remove",
        handFinishUrl: prefix + "/handFinish",
        handInvalidUrl: prefix + "/handInvalid",
        changeJobStatusUrl: prefix + "/changeJobStatus",
        sortName: "createTime",
        sortOrder: "desc",
        modalName: "入库作业信息",
        singleSelect: true,
        sureUrl: prefix + "/sure",
        auditUrl: prefix + "/audit",
        receiptSureUrl: prefix + "/receiptSure",
        receiptCancleUrl: prefix + "/receiptCancle",
        deleteAllUrl: prefix + "/deleteAll",
        columns: [{
            checkbox: true
        },
            {
                field: 'jobId',
                title: '作业id'
            },
            {
                field: 'status',
                title: '作业状态',
                halign: 'center',
                align:'center',
                sortable: true,
                formatter: function(value, row, index) {
                    return $.table.selectDictLabel(jobStatusDatas, value);
                }
            },

            {
                field: 'taskNo',
                title: '任务号'
            },

            {
                field: 'trayCode',
                title: '托盘条码'
            },
            {
                field: 'supplierId',
                title: '供应商'
            },
            // {
            //     field: 'entranceId',
            //     title: '入口'
            // },
            {
                field: 'roadwayId',
                title: '巷道'
            },
            {
                field: 'cargoSpaceId',
                title: '货位'
            },
            {
                field: 'priority',
                title: '优先级'
            },
            {
                field: 'executionPhase',
                title: '执行阶段',
                halign: 'center',
                align:'center',
                sortable: true,
                formatter: function (value, row, index) {
                    return $.table.selectDictLabel(jobExeDatas, value);

                }
            },
            {
                field: 'inOrOut',
                title: '入库类型',
                halign: 'center',
                align:'center',
                sortable: true,
                formatter: function (value, row, index) {
                    return $.table.selectDictLabel(jobTypeDatas, value);

                }
            },
            {
                field: 'createTime',
                title: '创建时间'
            },
            {
                field: 'startTime',
                title: '开始时间'
            },
            {
                field: 'finishTime',
                title: '完成时间'
            },

            // {
            //     field: 'stockSource',
            //     title: '库存来源'
            // }


            ],
        //双击显示子表
        onClickRow: function (t, e) {
                options2.url = ctx + "mydo/detail/list?jobId=" + t.jobId;
                $('#bootstrap-table2').bootstrapTable("refresh", options2)
            }
    };
    $.table.init(options);
    // $('#bootstrap-table').bootstrapTable(options)

    function handFinish() {
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录！");
            return;
        }
        if (rows.length > 1) {
            $.modal.alertWarning("只允许选择一条记录！");
            return;
        }
        $.modal.confirm("确认要手动完成选中的" + rows.length + "条作业吗?", function () {
            var url = table.options.handFinishUrl;
            var data = {"ids": rows.join()};
            $.operate.submit(url, "post", "json", data);
        });
    }

    function handInvalid() {

        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录！");
            return;
        }
        if (rows.length > 1) {
            $.modal.alertWarning("只允许选择一条记录！");
            return;
        }
        $.modal.confirm("确认要手动作废选中的" + rows.length + "条作业吗?", function () {
            var url = table.options.handInvalidUrl;
            var data = {"ids": rows.join()};
            $.operate.submit(url, "post", "json", data);
        });
    }

    function changeJobStatus() {
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录！");
            return;
        }
        if (rows.length > 1) {
            $.modal.alertWarning("只允许选择一条记录！");
            return;
        }
        $.modal.confirm("确认要更改选中的" + rows.length + "条作业状态吗?", function () {
            var url = table.options.changeJobStatusUrl;
            var data = {"ids": rows.join()};
            $.operate.submit(url, "post", "json", data);
        });
    }
</script>
</body>
</html>